package com.turtle3d.visualizator;

import javax.media.j3d.Shape3D;
import javax.vecmath.Point3f;

import com.sun.j3d.utils.geometry.GeometryInfo;
import com.sun.j3d.utils.geometry.NormalGenerator;

public class MyPyramid extends Shape3D {
	
	public MyPyramid(float side){
						
		Point3f lower[] = new Point3f[4];
		
		float radius = side/(float)Math.sqrt(2);
		Point3f upper = new Point3f(0,radius,0);
		
		for(int i=0;i<4;i++){
			double x = Math.sin(i*2*Math.PI/4);
			double y = Math.cos(i*2*Math.PI/4);
			
			lower[i] = new Point3f((float)x*radius,0,(float)y*radius);								
		}
				
		//per polygon
		Point3f points[] = new Point3f[16];
		points[0] = lower[3];
		points[1] = lower[2];
		points[2] = lower[1];
		points[3] = lower[0];
		
		points[4] = lower[0];
		points[5] = lower[1];
		points[6] = upper;
		
		points[7] = lower[1];
		points[8] = lower[2];
		points[9] = upper;
		
		points[10] = lower[2];
		points[11] = lower[3];
		points[12] = upper;
		
		points[13] = lower[3];
		points[14] = lower[0];
		points[15] = upper;				
              
		int[] stripCounts = new int[5];
		stripCounts[0] = 4;
		stripCounts[1] = 3;
		stripCounts[2] = 3;
		stripCounts[3] = 3;
		stripCounts[4] = 3;		
		
		int[] contourCount = new int[5];
		for(int i=0;i<5;i++)
			contourCount[i] = 1;		     
		
		GeometryInfo gInf = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);

		gInf.setCoordinates(points);
		gInf.setStripCounts(stripCounts);
		gInf.setContourCounts(contourCount);
		
		NormalGenerator ng = new NormalGenerator();
		ng.setCreaseAngle((float) Math.toRadians(45));
		ng.generateNormals(gInf);
		this.setGeometry(gInf.getGeometryArray());
     
		
	
		
	}
	
}
